<template>
  <div>
    <!-- 模糊查询 -->
    <div style="margin-top: 10px; font-weight: bold;float: left; width: 100%;">
      <el-form :inline="true" :model="queryTop" class="demo-form-inline" size="medium">
        <el-form-item label="厂家名称" style="margin-right: 5%;display: block;float: left;">
          <el-input v-model="queryTop.fName" placeholder="请输入厂家名称"></el-input>
        </el-form-item>
        <el-form-item label="关键字" style="margin-right: 5%;display: block;float: left;">
          <el-input v-model="queryTop.fKey" placeholder="请输入关键字"></el-input>
        </el-form-item>
        <el-form-item label="厂家电话" style="margin-right: 5%;display: block;float: left;">
          <el-input v-model="queryTop.fPhone" placeholder="请输入厂家电话"></el-input>
        </el-form-item>
        <el-form-item label="状态" style="margin-right: 5%;display: block;float: left;">
          <el-select v-model="queryTop.fStatus" placeholder="可用状态">
            <el-option label="正常" value="1"></el-option>
            <el-option label="异常" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" style="margin-right: 5%;display: block;float: left;">
          <el-date-picker v-model="queryTop.fCreatetime" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item style="margin-right: 5%;float: left;">
          <el-button type="primary" size="small" icon="el-icon-search">查询</el-button>
          <el-button type="primary" size="small" icon="el-icon-refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 按钮 -->
    <div style="margin-bottom:10px;float: left;">
      <el-button size="small" type="primary" icon="el-icon-plus" @click="fTopInsert()">新增</el-button>
      <el-button size="small" type="success" icon="el-icon-edit">修改</el-button>
      <el-button size="small" type="danger" icon="el-icon-delete">删除</el-button>
    </div>

    <!-- 表单 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="厂家名称" :label-width="formLabelWidth">
          <el-input v-model="form.fName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="厂家编码" :label-width="formLabelWidth">
          <el-input v-model="form.fEncoder" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系人" :label-width="formLabelWidth">
          <el-input v-model="form.fContacts" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" :label-width="formLabelWidth">
          <el-input v-model="form.fPhone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="关键字" :label-width="formLabelWidth">
          <el-input v-model="form.fKey" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <template>
            <el-radio v-model="form.fStatus" label="1">正常</el-radio>
            <el-radio v-model="form.fStatus" label="2">异常</el-radio>
          </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 表格 -->
    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange" size="small" border :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="fId" label="厂家ID">
      </el-table-column>
      <el-table-column prop="fName" label="厂家名称" width="300px">
      </el-table-column>
      <el-table-column prop="fEncoder" label="厂家编码">
      </el-table-column>
      <el-table-column prop="fContacts" label="联系人">
      </el-table-column>
      <el-table-column prop="fPhone" label="电话">
      </el-table-column>
      <el-table-column prop="fKey" label="关键字">
      </el-table-column>
      <el-table-column prop="fStatus" label="状态">
        <template slot-scope="scope">
          {{ scope.row.fStatus == 1 ? "正常" : "异常" }}
        </template>
      </el-table-column>
      <el-table-column prop="fCreatetime" label="创建时间">
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" icon="el-icon-edit" @click="fTableUpdate(scope.row)">修改</el-button>
          <el-button type="text" size="small" icon="el-icon-delete" @click="fTableDelete(scope.row.fId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.current"
      :page-sizes="[10, 20, 30, 40]" :page-size="page.size" layout="total, sizes, prev, pager, next, jumper"
      :total="page.total" style="margin-top: 5px;">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 头部查询
      queryTop: {
        fName: '',
        fKey: '',
        fPhone: '',
        fStatus: "",
        fCreatetime: ''
      },
      topLabelWidth: '120px',
      // 表单
      dialogFormVisible: false,
      title: '',
      form: {
        fName: '',
        fEncoder: '',
        fContacts: '',
        fPhone: '',
        fKey: '',
        fStatus: '1',
        fCreatetime: ''
      },
      formLabelWidth: '120px',
      // 表格
      tableData: [{
        fId: '1',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '1',
        fCreatetime: '2030-01-01 00:00:00'
      }, {
        fId: '2',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '2',
        fCreatetime: '2030-01-01 00:00:00'
      }, {
        fId: '3',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '1',
        fCreatetime: '2030-01-01 00:00:00'
      }, {
        fId: '4',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '1',
        fCreatetime: '2030-01-01 00:00:00'
      }, {
        fId: '5',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '1',
        fCreatetime: '2030-01-01 00:00:00'
      }, {
        fId: '6',
        fName: '云南白药集团股份有限公司',
        fEncoder: '000538',
        fContacts: '孙大娘',
        fPhone: '0871-66350538',
        fKey: 'ynby',
        fStatus: '2',
        fCreatetime: '2030-01-01 00:00:00'
      }],
      multipleSelection: [],
      // 分页
      page: {
        current: 1,
        size: 10,
        tatal: 10
      }
    }
  },

  methods: {
    // 表格
    // 打开添加表单
    fTopInsert() {
      this.title = '添加';
      this.dialogFormVisible = true;
      this.form = {
        fName: '',
        fEncoder: '',
        fContacts: '',
        fPhone: '',
        fKey: '',
        fStatus: '1',
        fCreatetime: ''
      };
    },
    // 打开修改表单
    fTableUpdate(obj) {
      this.title = '修改';
      this.dialogFormVisible = true;
      this.form = this.$qs.parse(this.$qs.stringify(obj));
    },
    // 删除
    fTableDelete(fId) {
      this.$confirm('此操作将永久删除该厂家信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
}
</script>
<style scoped>
body {
  margin: 0%;
  padding: 0%;
}
</style>